package com.haixiaoke.saas.manage.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.user.domain.UserConsumer;
import com.haixiaoke.saas.user.service.IUserConsumerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * C端用户Controller
 * 
 * @author panda
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/manage/user/consumer")
public class ManageUserConsumerController extends BaseController {
    @Autowired
    private IUserConsumerService userConsumerService;

    /**
     * 查询C端用户列表
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserConsumer userConsumer) {
        startPage();
        List<UserConsumer> list = userConsumerService.selectUserConsumerList(userConsumer);
        return getDataTable(list);
    }

    /**
     * 导出C端用户列表
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:export')")
    @Log(title = "C端用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserConsumer userConsumer) {
        List<UserConsumer> list = userConsumerService.selectUserConsumerList(userConsumer);
        ExcelUtil<UserConsumer> util = new ExcelUtil<UserConsumer>(UserConsumer.class);
        util.exportExcel(response, list, "C端用户数据");
    }

    /**
     * 获取C端用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(userConsumerService.selectUserConsumerByUserId(userId));
    }

    /**
     * 新增C端用户
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:add')")
    @Log(title = "C端用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserConsumer userConsumer) {
        return toAjax(userConsumerService.insertUserConsumer(userConsumer));
    }

    /**
     * 修改C端用户
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:edit')")
    @Log(title = "C端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserConsumer userConsumer) {
        return toAjax(userConsumerService.updateUserConsumer(userConsumer));
    }

    /**
     * 删除C端用户
     */
    @PreAuthorize("@ss.hasPermi('business:consumer:remove')")
    @Log(title = "C端用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(userConsumerService.deleteUserConsumerByUserIds(userIds));
    }
}
